<template>
  <div class="block" style="width: 100% ;height: 100%">
    <el-date-picker
        v-model="intervalTime"
        type="daterange"
        range-separator="至"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
        :default-time="['00:00:00', '23:59:59']"
        :picker-options="pickerOptions">
    </el-date-picker>
    <el-button @click="queryAllocationAdjust">查询</el-button>
    <el-table
        :data="tableData"
        border
        style="width: 100%">
      <el-table-column prop="createdTime" label="日期" :formatter="formatDate">
      </el-table-column>
      <el-table-column prop="studentName" label="姓名">
      </el-table-column>
      <el-table-column prop="outRoomBuildingName" label="转出楼栋">
      </el-table-column>
      <el-table-column prop="outRoomName" label="转出房间" >
      </el-table-column>
      <el-table-column prop="inRoomBuildingName" label="转入楼栋" >
      </el-table-column>
      <el-table-column prop="inRoomName" label="转入房间">
      </el-table-column>
      <el-table-column prop="leaderName" label="审核领导">
      </el-table-column>
      <el-table-column prop="state" label="状态">
      </el-table-column>
    </el-table>
    <div class="block">
      <el-pagination
          @current-change="handleCurrentChange"
          :current-page="pageNo"
          :page-size="pageSize"
          layout="total, prev, pager, next, jumper"
          >
      </el-pagination>
    </div>
  </div>
</template>
<script>

import {selectAllocationAdjust} from '../../../../api/leader'

export default {
  data () {
    return {
      total: 0,
      pageNo: 1,
      pageSize: 10,
      intervalTime: null,
      selectType: null,
      lastType: null,
      tableData: [],
      pickerOptions: {
        disabledDate (time) {
          const today = new Date()
          today.setHours(23, 59, 59, 999)
          return time.getTime() > today.getTime()
        }
      }
    }
  },
  methods: {
    formatDate (row) {
      const date = new Date(row.createdTime)
      const year = date.getFullYear()
      const month = (date.getMonth() + 1).toString().padStart(2, '0')
      const day = date.getDate().toString().padStart(2, '0')
      return `${year}年${month}月${day}日`
    },
    handleCurrentChange (newPage) {
      this.pageNo = newPage
      this.queryAllocationAdjust()
    },
    queryAllocationAdjust () {
      if (this.intervalTime === null || this.intervalTime === '') {
        this.$message({
          type: 'error',
          message: '请选择时间!'
        })
        return
      }
      let DOT = {
        pageNo: this.pageNo,
        pageSize: this.pageSize,
        data: {
          startTime: this.intervalTime[0],
          endTime: this.intervalTime[1]
        }
      }
      selectAllocationAdjust(DOT).then(res => {
        if (res.status === true) {
          this.tableData = res.data
        } else {
          this.$message({
            type: 'error',
            message: '查询失败!'
          })
        }
      })
    }
  }
}
</script>
<style>
</style>
